import DataQuery from "./DataQuery"
let dbCollection = [
    {
        name: "administrators",
        data: [
            {
                userName: "huatie",
                password: "huatie2021",
            },
            {
                userName: "huatie_admin",
                password: "huatie_admin2021",
            },
        ],
    },
    {
        name: "exercises",
        data: [
            {
                "CategoryName": "大类名称",
                "Interval": [
                    {
                        "IntervalName": "小类名称0-1",
                        "judges": [
                            {
                                "answer": true,
                                "detailedAnswer": "判断详细解答",
                                "subject": "判断题题目描述"
                            }
                        ],
                        "multipleChoices": [
                            {
                                "answer": "ABC",
                                "detailedAnswer": "多选详细解答",
                                "items": [
                                    "选项A",
                                    "选项B",
                                    "选项C",
                                    "选项D"
                                ],
                                "subject": "多选题目描述"
                            }
                        ],
                        "shortAnswer": [
                            {
                                "detailedAnswer": "简答详细解答",
                                "subject": "题目描述"
                            }
                        ],
                        "singleChoices": [
                            {
                                "answer": "C",
                                "detailedAnswer": "单选详细解答",
                                "items": [
                                    "选项A",
                                    "选项B",
                                    "选项C",
                                    "选项D"
                                ],
                                "subject": "题目描述题目描述题目描述题目描述题目描述题目描述题目描述题目描述题目描述题目描述题目描述"
                            },
                            {
                                "answer": "C",
                                "detailedAnswer": "单选详细解答",
                                "items": [
                                    "选项A",
                                    "选项B",
                                    "选项C",
                                    "选项D"
                                ],
                                "subject": "题目描述题目描述题目描述题目描述题目描述题目描述题目描述题目描述题目描述题目描述题目描述"
                            },
                            {
                                "answer": "A",
                                "detailedAnswer": "    单选详细解答详细解答详细解答详细解答详细解答详细解答详细解答详细\n\r解答详细解答详细解答详详细解答详细解答详细解答详细解答详细解答",
                                "items": [
                                    "选项A",
                                    "选项B",
                                    "选项C",
                                    "选项D"
                                ],
                                "subject": "题目描述题目描述题目描述题目描述题目描述题目描述题目描述题目描述题目描述题目描述题目描述"
                            }
                        ]
                    },
                    {
                        "IntervalName": "小类名称0-2",
                        "judges": [
                            {
                                "answer": true,
                                "detailedAnswer": "判断详细解答",
                                "subject": "题目描述"
                            }
                        ],
                        "multipleChoices": [
                            {
                                "answer": [
                                    "0",
                                    "2"
                                ],
                                "detailedAnswer": "多选详细解答",
                                "items": [
                                    "选项A",
                                    "选项B",
                                    "选项C",
                                    "选项D"
                                ],
                                "subject": "题目描述"
                            }
                        ],
                        "shortAnswer": [
                            {
                                "detailedAnswer": "简答详细解答",
                                "subject": "题目描述"
                            }
                        ],
                        "singleChoices": [
                            {
                                "answer": 2,
                                "detailedAnswer": "单选详细解答",
                                "items": [
                                    "选项A",
                                    "选项B",
                                    "选项C",
                                    "选项D"
                                ],
                                "subject": "题目描述"
                            }
                        ]
                    },
                    {
                        "IntervalName": "小类名称0-3",
                        "judges": [
                            {
                                "answer": true,
                                "detailedAnswer": "判断详细解答",
                                "subject": "题目描述"
                            }
                        ],
                        "multipleChoices": [
                            {
                                "answer": "BD",
                                "detailedAnswer": "多选详细解答",
                                "items": [
                                    "选项A",
                                    "选项B",
                                    "选项C",
                                    "选项D"
                                ],
                                "subject": "题目描述"
                            }
                        ],
                        "shortAnswer": [
                            {
                                "detailedAnswer": "简答详细解答",
                                "subject": "题目描述"
                            }
                        ],
                        "singleChoices": [
                            {
                                "answer": "A",
                                "detailedAnswer": "单选详细解答",
                                "items": [
                                    "选项A",
                                    "选项B",
                                    "选项C",
                                    "选项D"
                                ],
                                "subject": "题目描述"
                            }
                        ]
                    }
                ],
                "_id": "9e7190f16199f3e9070a34ee765ecd57"
            },
            {
                "CategoryName": "大类名称2",
                "Interval": [
                    {
                        "IntervalName": "小类名称2",
                        "judges": [
                            {
                                "answer": true,
                                "detailedAnswer": "判断详细解答",
                                "subject": "题目描述"
                            }
                        ],
                        "multipleChoices": [
                            {
                                "answer": "ABCD",
                                "detailedAnswer": "多选详细解答",
                                "items": [
                                    "选项A",
                                    "选项B",
                                    "选项C",
                                    "选项D"
                                ],
                                "subject": "题目描述"
                            }
                        ],
                        "shortAnswer": [
                            {
                                "detailedAnswer": "简答详细解答",
                                "subject": "题目描述"
                            }
                        ],
                        "singleChoices": [
                            {
                                "answer": "B",
                                "detailedAnswer": "单选详细解答",
                                "items": [
                                    "选项A",
                                    "选项B",
                                    "选项C",
                                    "选项D"
                                ],
                                "subject": "题目描述"
                            }
                        ]
                    }
                ],
                "_id": "9e7190f16199f3e9070a34ee765ecd54"
            }
        ],
    },

]
export default {
    methods: {
        async findData(collectionName: string) {
            let item = dbCollection.find((item) => {
                return item.name === collectionName;
            });
            if (item != undefined) {
                return item.data;
            }
            let promise = DataQuery.methods.queryCollection(collectionName);
            let result = await promise;
            dbCollection.push({name: collectionName, data: result});
            return result;
        },
        async obtainData(collectionName: string) {
            let result = undefined;
            switch (collectionName) {
                case "administrators":
                case "exercises":
                    result = await this.findData(collectionName);
                    break;
            }
            return result;
        },
        GetData(collectionName: string) {
            let item = dbCollection.find((item) => {
                return item.name === collectionName;
            });
            if (item != undefined) {
                return item.data;
            }
            return undefined;
        }
    },
};